from kivy.uix.widget import Widget
from kivy.properties import DictProperty

from goblinoid.services.activityservice import ActivityService


class ActivityManager(Widget):
    activity_services = DictProperty()

    def add_activity(self, activity):
        activity_id = activity.id
        if activity_id not in self.activity_services:
            self.activity_services[activity_id] = ActivityService(
                activity=activity)
        else:
            self.activity_services[activity_id].update_activity(activity)

    def get_activity_service(self, activity_id):
        return self.activity_services[activity_id]

    def clear_activities(self):
        for activity_service in self.activity_services.values():
            activity_service.clear_activity_data()
